package com.shoppingmall.fragment;

import android.os.Bundle;
import android.view.View;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.example.zyh.toolslib.base.BaseFragment;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;
import com.shoppingmall.R;
import com.shoppingmall.activity.mine.PendingPaymentOrderDetailsActivity;
import com.shoppingmall.adapter.OrderListAdapter;
import com.shoppingmall.bean.OrderBean;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;

/**
 * 2020/3/19
 * 描述：订单列表
 */
public class MineOrderListFragment extends BaseFragment {

    @BindView(R.id.rv_content_list)
    RecyclerView rvContentList;
    @BindView(R.id.smart_refresh)
    SmartRefreshLayout smartRefresh;

    private int status = 0;
    private OrderListAdapter mAdapter;
    private List<OrderBean> mData;

    public static MineOrderListFragment newInstance(int status) {

        Bundle args = new Bundle();
        args.putInt("status", status);
        MineOrderListFragment fragment = new MineOrderListFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected int initLayout() {
        return R.layout.fragment_recycleview;
    }

    @Override
    protected void initView(View rootView) {
        status = getArguments().getInt("status");
        smartRefresh.setOnRefreshLoadMoreListener(new OnRefreshLoadMoreListener() {
            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {

            }

            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {

            }
        });
    }

    @Override
    protected void initData() {


        mData = new ArrayList<>();
        if (status == 0) {
            mData.add(new OrderBean(1));
            mData.add(new OrderBean(2));
            mData.add(new OrderBean(3));
            mData.add(new OrderBean(4));
        }
        if (status == 1) {
            mData.add(new OrderBean(1));
        }
        if (status == 2) {
            mData.add(new OrderBean(2));
        }

        if (status == 3) {
            mData.add(new OrderBean(3));
        }

        if (status == 4) {
            mData.add(new OrderBean(4));
        }

        mAdapter = new OrderListAdapter(mData);
        rvContentList.setLayoutManager(new LinearLayoutManager(mActivity));
        rvContentList.setAdapter(mAdapter);
        mAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                if (view.getId() == R.id.tv_go_to_pay) {
                    ToastUtils.showShort("去付款");
                } else if (view.getId() == R.id.tv_cancel_order) {

                    if (mData.get(position).getStatus() == 3) {

                        ToastUtils.showShort("去付款");
                    } else if (mData.get(position).getStatus() == 4) {

                        ToastUtils.showShort("去评价");
                    }

                }
            }
        });
        mAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                ActivityUtils.startActivity(PendingPaymentOrderDetailsActivity.class);
            }
        });
    }
}
